package cn.slipi.admin.filter;

import cn.slipi.admin.common.servlet.MultiReadHttpServletRequest;
import cn.slipi.admin.common.utils.TraceUtil;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * TODO: 请添加描述
 *
 * @author lee
 * @date 2019-08-15
 * @since 1.0.0
 */
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ContextFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) {
        try {
            TraceUtil.traceStart();
            chain.doFilter(new MultiReadHttpServletRequest(request), response);
        } catch (IOException | ServletException e) {
            TraceUtil.traceEnd();
        }
    }
}
